C (74/254)

From:Andrew Bell
Date:20 Apr 00 at 12:16:28
Subject:Re: How to change stack

Hi Andrzej,

On 20-Apr-00 you wrote: Re: [amiga-c] Re: How to change stack

> Wednesday, April 19, 2000, you wrote:
>> [...about StackSwap and StackSwapStruct...]
>
> Thanks. I wrote some test proggy. But something id wrong. It hangs
> on first StackSwap func. Can someone help me to solve that?

At a guess, I'd say you're linking in stubs for exec.library. When you
call StackSwap() via a stub, the stub attempts to pull the return
address and registers off the new stack when it exits, causing an
instant crash. Most compilers these days allow you to omit stubs and
call Amiga OS functions directly (using register definitions stored
in #pragams). This should solve your problem. Check your compiler's
docs for more info on how to do this.

Another thing to watch out for is, you *MUST* call your StackSwap()
pair within the same sub-routine (which stops the stack pointer from
moving). Also define the local variables of that routine as static so
the compiler doesn't place them onto the stack. Note that all the
automatic variables for that routine will become invalid, until the
old stack is swapped back in.

And lastly, always check your existing stack size before swapping in a
new stack. If you swap in a 16K stack all the time, you're
effectively hardcoding this size into your program. Some heavily
patched systems can eat up a lot of stack space, so 16K can vanish
very easily. It's best to check if your current stack size is
adequate before doing the swap. Doing so will allow users to use
commands like "stack" to give your program even more stack space, in
case their system is unusually very stack hungry.

Regards, Andrew Bell.



+----------------------------------------+
email: mailto:andrew.ab2000@bigfoot.com
web: http://www.andrewb.exl.co.uk
+----------------------------------------+
(Did I mention I'm good looking?) (Quiet?) (Shy?) (Undersexed?)

------------------------------------------------------------------------
You can win $1000!
Time-limited offer. Enter today at:
http://click.egroups.com/1/2864/1/_/451227/_/956231603/
------------------------------------------------------------------------